#########################
## BLIS/Swayable: Data ##
#########################

# File Description: 
  # Read in the merged data from Swayable. 
  # Basic data cleaning to replicate report findings.
  # Read in all necessary packages for analyses.
# Date Last Updated: 2 May 2025

#########################

# Clear the workspace 
rm(list=ls())

# Load necessary packages
library(magrittr)
library(arsenal)
library(tidyverse)
library(ggeffects)
library(broom)
library(dotwhisker)
library(stargazer)
library(showtext)
library(kableExtra)

# Read in the raw data
df <- read.csv("BLIS_Swayable_2025.csv")

# Create a variable to drop respondents who are not Native Hawaiian, American Indian, or Alaska Native.
df <- df %>%
  mutate(drop_respondents = case_when(Ethnicity..Pacific.Islander == T & Ethnicity..Alaska.Native == F & Ethnicity..American.Indian.Native.American == F & Ethnicity..Native.Hawaiian.Kanaka.Maoli == F & Ethnicity..First.Nations..Inuit.or.Metis == F ~ T,                                Ethnicity..Indigenous.People.Tribe.from.Mexico..Central.or.South.America == T & Ethnicity..Alaska.Native == F & Ethnicity..American.Indian.Native.American == F & Ethnicity..Native.Hawaiian.Kanaka.Maoli == F & Ethnicity..First.Nations..Inuit.or.Metis == F ~ T,
                                      TRUE ~ F))

df$treatment <- factor(df$treatment, levels = c("Control", "Reparations",
                                                        "Land Back", "Both"))

# Drop these respondents for the report analytic sample
df <- df %>%
  filter(drop_respondents == F)

# Drop respondents who do not report being over 18 years old
df <- df %>%
  filter(Age >= 18)

# Clean variables for further analyses

df <- df %>%
  mutate(summarized_party = case_when(Party == "republican" ~ "Republican",
                                      Party == "democrat" ~ "Democrat",
                                      TRUE ~ "Independent or Other"),
         age_groups = case_when(Age >= 18 & Age <= 25 ~ "18-25",
                                Age > 25 & Age <= 35 ~ "26-35",
                                Age > 35 & Age <= 45 ~ "36-45",
                                Age > 45 & Age <= 55 ~ "46-55",
                                Age > 55 & Age <= 65 ~ "56-65",
                                Age > 65 ~ "66+"),
         Income = case_when(What.is.the.total.annual.income.of.your.household.before.taxes. == "100-150-k" ~ "$100-150K",
                            What.is.the.total.annual.income.of.your.household.before.taxes. == "under-20-k" ~ "Under $20K",
                            What.is.the.total.annual.income.of.your.household.before.taxes. == "20-40-k" | What.is.the.total.annual.income.of.your.household.before.taxes. == "40-60k" ~ "$20-60K",
                            What.is.the.total.annual.income.of.your.household.before.taxes. == "60-80-k" | What.is.the.total.annual.income.of.your.household.before.taxes. == "80-100-k" ~ "$60-100K",
                            What.is.the.total.annual.income.of.your.household.before.taxes. == "150-200-k" | What.is.the.total.annual.income.of.your.household.before.taxes. == "over-200-k" ~ "Over $150K",
                            TRUE ~ NA),
         Income = factor(Income, levels = c("Under $20K", "$20-60K", "$60-100K", "$100-150K", "Over $150K")))
